package com.example.internetplus.utils;

import com.example.internetplus.domain.po.HandStress;
import org.springframework.stereotype.Component;
import java.util.List;

@Component
public class MathUtil {
    public List<Double>fitting(List<HandStress> handStress){
        return null;
    }
    //最小二乘法
    public Double leastSquares(List<Double>real, List<Double>fitter){
        if (real == null){
            throw new RuntimeException("最小二乘法真实值为空");
        }
        if (fitter == null){
            throw new RuntimeException("最小二乘法拟合值为空");
        }
        Double result = 0.0;
        for(int i =0; i < real.size(); i++){
            Double reality = real.get(i);
            Double fitting = fitter.get(i);
            result += (fitting - reality) * (fitting - reality);
        }
        return result;
    }
}
